<?php 
class page_show extends MX_Controller{
	public function index($page_link){
		//remplacer page_link => id page

		$setting=$this->load->Module('setting/data');
		
		$page=$this->model()->show($page_link);
		
		//si la page est non valide
		if(!$page){
		
		
			$data=array(
					'title'=>"Cette annonce est désactivée",
					'description'=>"Annonce non-trouvable",
					'keywords'=>''
			);

			$data=$setting->data($data);
			$this->view(
					array('header',
							'annonce-desactive',
							'footer'),
									$data); // Display the page
			return false;
		}
		$title=$page->title;
		$description=self::truncate(strip_tags($page->metadescription),150);
		$keywords=$page->metakeywords;
		
		$data=array(
				'title'=>$title,
				'description'=>$description,
				'keywords'=>$keywords,
				'filter'=>'',
				'page'=>$page
		);

		$data=$setting->data($data);
		$data['nav_class']['offre']='active';
		
		$this->view(
				array('header',
					  'page',
					  'footer'),
				$data); // Display the page
		
	}
	private function truncate($string, $limit, $break=" ", $pad="") { 
		// return with no change if string is shorter than $limit 
		if(strlen($string) <= $limit) 
			return $string; 
		$string = substr($string, 0, $limit); 
		if(false !== ($breakpoint = strrpos($string, $break)))
			$string = substr($string, 0, $breakpoint); 
		return $string . $pad; 
	}
}